<?

//Data loading
$title='DAFTAR NOTA';

if (GetParam("office","")) $perush = GetCompany (GetParam("office",""));
else $perush = GetCompany (GetOfficeID());
if (GetParam("location","")) $perush .= ' (DEPO: '.GetParam("location","").')';

$page   = 'PAGE';

$DEFINE_FONT=0;
$pdf=new PDFReport("P","mm","Letter");
$pdf->AddPage();
$Result = GridList ("", "", "");
$pdf->GridTable($Result);
$pdf->Output();


function GridList ($Space, $Index, $ParentID) {
			global $Curr,$DBConnection;


 			$SQL = "SELECT *, DATE_FORMAT(tglbkt,'%d/%m/%y') as trdate FROM ais_memorial WHERE nobkt like 'N%' AND urut ='999'";
 			if (GetParam("office","")) $SQL .= " AND ktrasl='".GetParam("office","")."'";

      if (GetParam("location",""))
                    $SQL .= " AND location = '".GetParam("location","")."' ";

 			if (GetParam("fromDate","")) {
			    list($day,$month,$year) = explode("/",GetParam("fromDate",""));
			    $fromDate = date('Y-m-d',mktime(0,0,0,$month,$day,$year));
	 				$SQL .= " AND tglbkt>='$fromDate'";
      }

 			if (GetParam("toDate","")) {
			    list($day,$month,$year) = explode("/",GetParam("toDate",""));
			    $toDate   = date('Y-m-d',mktime(0,0,0,$month,$day,$year));	 			
	 				$SQL .= " AND tglbkt<='$toDate'";
      }


 			if (GetParam("curr","")) {
	 			$SQL .= " AND curr='".GetParam("curr","")."' ";
      }

      $SQL .= " ORDER BY nobkt";        
			$MyResult = $DBConnection->dbc->get_results($SQL,ARRAY_A);
			return $MyResult;
} 


class PDFReport extends PDF {

	function Header() {
		global $title,$perush,$page,$DEFINE_FONT;
		if ($DEFINE_FONT==0) {
			$this->AddFont('Arial','','arialn.php');
			$DEFINE_FONT=1;
		}
		
		$this->SetFont('Arial','',11);
    $this->Cell(200,5,$perush,0,1,'C',0);
    if (GetParam("curr","")) $this->Cell(200,5,$title." (".GetParam("curr","").")",0,1,'C',0);
    else $this->Cell(200,5,$title,0,1,'C',0);
    $this->Cell(200,5,"PERIOD: ".GetParam("fromDate","")." TO ".GetParam("toDate",""),0,1,'C',0);
    $this->Cell(195,5,$page." ".$this->PageNo(),0,1,'R',0);
    $this->SetLeftMargin(5);
//    $this->Line(5,30,210,30);
    $this->Ln();

	  //Header
	  //Column widths
    $w=array(5,20,20,15,60,40,20,20);
    $this->SetFont('Arial','',8);
    $this->Cell($w[0],7,"NO",1,0,'C',0);
    $this->Cell($w[1],7,"DEBET",1,0,'C',0);
    $this->Cell($w[2],7,"CREDIT",1,0,'C',0);
    $this->Cell($w[3],7,"DATE",1,0,'C',0);
		$this->Cell($w[4],7,"FOR / FROM",1,0,'C',0);	    
		$this->Cell($w[5],7,"DESCRIPTION",1,0,'C',0);
		$this->Cell($w[6],7,"DEBET",1,0,'C',0);
		$this->Cell($w[7],7,"CREDIT",1,0,'C',0);
    $this->Ln(); 
	}

	function GridTable($MyResult) {
	    //Column widths
			global $Curr,$DBConnection;	    
	    $w=array(5,20,20,15,60,40,20,20);
	    //Data
      if ($MyResult)
	    foreach($MyResult as $row)
	    {
			    if (substr($row["nobkt"],0,2)=='ND') $row["jumlah1"] = $row["jumlah"];
			    else $row["jumlah2"] = $row["jumlah"];
			    $totaldebet = $totaldebet + $row["jumlah1"];
			    $totalcredit = $totalcredit + $row["jumlah2"];
					$n++;
					$Curr = $row["curr"];
			    $this->Cell($w[0],7,$n.".",'LR',0,'R');
		if (substr($row["nobkt"],0,2)=='ND') {
	        	$this->Cell($w[1],7,$row["nobkt"],'LR');
	      	} else {
	      		$this->Cell($w[1],7,"",'LR');
	      	}
	      	if (substr($row["nobkt"],0,2)=='NK') {
			$this->Cell($w[2],7,$row["nobkt"],'LR');
	        	
	        } else {
	        	$this->Cell($w[2],7,"",'LR');
	        }
	        $this->Cell($w[3],7,$row["trdate"],'LR',0,'C');
					$this->Cell($w[4],7,$row["debnam"],'LR');
	        $this->Cell($w[5],7,$row["uraian"],'LR');
	        $this->Cell($w[6],7,FormatNumber($row["jumlah1"],2),'LR',0,'R');
					$this->Cell($w[7],7,FormatNumber($row["jumlah2"],2),'LR',0,'R');
	        $this->Ln();
	    }
	        $this->Cell($w[0]+$w[1]+$w[2]+$w[3]+$w[4]+$w[5],7,"JUMLAH:",1,0,'R',0);
	        $this->Cell($w[6],7,FormatNumber($totaldebet,2),1,0,'R',0);
					$this->Cell($w[7],7,FormatNumber($totalcredit,2),1,0,'R',0);
	        $this->Ln();
	        $this->Ln();

	    		$this->Cell($w[0]+$w[1],7,"MENYETUJUI",0,0,'C');
	    		$this->Ln();$this->Ln();$this->Ln();
	    		$this->Cell($w[0]+$w[1],7,"( ................................... )",0,0,'C');
	    //Closure line
	}

	function Footer() {
	    //Closure line
	    //$this->Cell(200,0,'','T');
	}

}


?>
